package com.huike.controller.sys;

import com.huike.Position.dtos.PositionDto;
import com.huike.Position.dtos.PositionPageDTO;
import com.huike.Position.pojos.Position;
import com.huike.Position.vos.PositionVO;
import com.huike.result.PageResult;
import com.huike.result.Result;
import com.huike.service.sys.PositionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//岗位接口
@RestController
@RequestMapping("/api/position")
public class PositionController {

    @Autowired
    private PositionService positionService;
    //分页查询岗位数据
    @PostMapping("/list")
    public Result pageList(@RequestBody PositionPageDTO pageDTO) {
      PageResult pageResult = positionService.pageList(pageDTO);
        return Result.success(pageResult);
    }
    //添加岗位
    @PostMapping()
    public Result insertPosition(@RequestBody PositionDto dto){
        positionService.insertPosition(dto);
        return Result.success("成功");
    }

    @PutMapping
    public Result updatePosition(@RequestBody Position positionDTO){
        positionService.updatePosition(positionDTO);
        return Result.success("成功");
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
      PositionVO position = positionService.getById(id);
      return Result.success(position);
    }

    @DeleteMapping
    public Result deleteById(@RequestParam List<Integer> ids){
        positionService.deleteById(ids);
        return Result.success("成功");
    }


}
